package com.interview.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.interview.entity.Schedule;
import com.interview.mapper.ScheduleMapper;
import com.interview.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleServiceImpl implements ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;


    @Override
    public int saveSchedule(List<Schedule> drawLotsSchedules) {
        for (Schedule drawLotsSchedule : drawLotsSchedules) {
            scheduleMapper.insert(drawLotsSchedule);
        }

        return drawLotsSchedules.size();
    }

//    @Override
//    public List<DrawLotsSchedule> getDrawLotsAwaitList(String groupId) {
//        QueryWrapper<DrawLotsSchedule> scheduleQueryWrapper = new QueryWrapper<>();
//        scheduleQueryWrapper.eq("group_id", groupId);
//
//        List<DrawLotsSchedule> drawLotsSchedules = drawLotsScheduleMapper.selectList(scheduleQueryWrapper);
//        return drawLotsSchedules;
//    }

    @Override
    public List<String> getDrawLotsAwaitList(String groupId) {
        return scheduleMapper.getDrawLotsAwaitList(groupId);
    }

    @Override
    public void removeDrawLots(Schedule drawLotsSchedule) {
        QueryWrapper<Schedule> scheduleQueryWrapper = new QueryWrapper<>();
        scheduleQueryWrapper.eq("group_id", drawLotsSchedule.getGroupId());
        scheduleQueryWrapper.eq("number", drawLotsSchedule.getNumber());
        scheduleMapper.delete(scheduleQueryWrapper);

    }

    @Override
    public List<Schedule> getScheduleList() {
        List<Schedule> schedules = scheduleMapper.selectList(null);
        return schedules;
    }

    @Override
    public int clearExameeDrawLotsPool() {
        int delete = scheduleMapper.delete(null);
        return delete;
    }


}
